//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package objects;

import common.GlobalID;
import common.LogicRandom;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

public class MineProduction {
    private boolean Locked = true;
    private int currentLevel;
    private final LogicRandom randomizer = new LogicRandom();
    private final List<Integer> finished = new ArrayList();

    public MineProduction() {
    }

    public void addFinished(Integer ore) {
        this.finished.add(ore);
    }

    public void clearFinished() {
        this.finished.clear();
    }

    public List<Integer> getFinished() {
        return this.finished;
    }

    public int getFinishedSize() {
        return this.finished.size();
    }

    public void setLevel(int level) {
        this.currentLevel = level;
    }

    public void Unlock() {
        this.Locked = false;
    }

    public void Lock() {
        this.Locked = true;
    }

    public boolean isLocked() {
        return this.Locked;
    }

    public void initRandomVector(int vector) {
        this.randomizer.setIteratedRandomSeed(vector);
    }

    public List<Integer> useTool(String toolName) {
        boolean diamondPresent = false;
        MineToolEntry mte = Mine.getTool(toolName);
        int diamondChance = mte.getDiamondChance();
        int numOres = mte.getNumOres();
        int rndDiamond = this.randomizer.rand(100);
        if(rndDiamond < diamondChance) {
            diamondPresent = true;
        }

        ArrayList objects = new ArrayList();
        if(diamondPresent) {
            objects.add(Integer.valueOf(GlobalID.create(19, 1)));
        }

        for(int i = 0; i < numOres; ++i) {
            objects.add(this.getRandomMineGoodData());
        }

        return objects;
    }

    public Integer getRandomMineGoodData() {
        Collection products = Mine.getGoods();
        if(products.size() < 1) {
            return null;
        } else {
            int probability = 0;
            Iterator eo = products.iterator();

            while(eo.hasNext()) {
                MineGoodEntry rnd = (MineGoodEntry)eo.next();
                if(rnd.getUnlockLevel().intValue() <= this.currentLevel) {
                    probability += rnd.getProbability().intValue();
                }
            }

            int var7 = this.randomizer.rand(probability);
            Object[] var8 = products.toArray();
            probability = 0;

            for(int i = 0; i < var8.length; ++i) {
                MineGoodEntry ec = (MineGoodEntry)var8[i];
                if(ec.getUnlockLevel().intValue() <= this.currentLevel) {
                    probability += ec.getProbability().intValue();
                    if(probability > var7) {
                        return Integer.valueOf(GlobalID.create(64, i));
                    }
                }
            }

            return null;
        }
    }
}
